<?
require_once( '../../includes/init.php');

function checkLogin() 
	{
		require_once ('../class_passport.php' );
		$clsPassport = new x_Passport;
		$clsPassport->appId = 10; // 通行证服务ID
		$clsPassport->encryptKey = 'k4kfEOJdi9asUWKKSDXxCKDIfjsoUH5Aa09dnAB'; // 私钥
		/****** 登陆认证 ******/
		// 第一步：
		$clsPassport->verify ();

		// 第二步，保存 Passport 信息到当前程序的 Session
		$userSession = $clsPassport->vars;
		/*
		这里为保存 Session 代码
		*/
		if ( $clsPassport->vars['app_user_id'] > 0 )
		{
			// 若账号已激活表示已登陆当前程序
		}
		// 注：无需每次都验证 Passport，可以先通过用户在当前程序本身的 Session 判断是否已登陆
        //print_r($userSession);die();

		/****** 获取程序列表 ******/
		// $appType : 程序的类型, 系统程序为 1, 游戏为 2
		$appList = $clsPassport->appGetList ( $appType );
		$_SESSION['union_username'] = $userSession["username"];
		$_SESSION['union_nickname'] = $userSession["nickname"];
		return $_SESSION['union_username'];
	}
if ($_SESSION['union_username'] =='') {
    checkLogin();
}

$smarty->cache_lifetime = 180;
//$smarty->caching = true;
$smarty->use_sub_dirs = true;

$siteObj=alps::newClass('mod_site','mod');

$siteInfo = $siteObj->getSiteInfo($_SERVER['HTTP_HOST']);                                                     //得到站点信息
if (empty($siteInfo)) die('请检查域名是否错误');
$smarty->assign('siteInfo',$siteInfo);
if ($siteInfo['site_status']==3) {
echo "<script>alert('网站审核没有通过');window.close();</script>";die;
}
$tplInfo = $siteObj->getTpl($siteInfo['template_id']);                                                         //得到模板
$tplpath=$tplInfo['temppath'];

$my_cache_id=md5($_SERVER['HTTP_HOST']);
if(!$smarty->is_cached($tplpath.'news/index.html',$my_cache_id)) {

	$jrtt_top = $siteObj->getnewslist(1,'',8);                                                                     // 今日头条top
	$smarty->assign('jrtt_top',$jrtt_top[0]);

	//$jrtt_mid = $siteObj->getnewslist(1,'',2,1);
																												   // 今日头条mid
	$jrtt_mid=array();
	for ($m=1;$m<3;$m++) {
		array_push($jrtt_mid,$jrtt_top[$m]);
	}
	$smarty->assign('jrtt_mid',$jrtt_mid);

	//$jrtt_bottom = $siteObj->getnewslist(1,'',5,3);                                                               // 今日头条bottom
	$jrtt_bottom=array();
	for ($n=3;$n<8;$n++) {
		array_push($jrtt_bottom,$jrtt_top[$n]);
	}
	$smarty->assign('jrtt_bottom',$jrtt_bottom);

	$wlsg = $siteObj->getnewslist('',102,10);                                                                          //武林三国
	$smarty->assign('wlsg',$wlsg);

	$wlzq1 = $siteObj->getnewslist('',101,10);                                                                          //武林足球1
	$smarty->assign('wlzq1',$wlzq1);

	$wlzq2 = $siteObj->getnewslist('',104,10);                                                                          //武林足球2
	$smarty->assign('wlzq2',$wlzq2);

	$wlyx = $siteObj->getnewslist('',103,10);                                                                          //武林英雄
	$smarty->assign('wlyx',$wlyx);

	$ptxw = $siteObj->getnewslist(2,'',5);                                                                          //平台新闻
	$smarty->assign('ptxw',$ptxw);

	$yjzx = $siteObj->getnewslist(3,'',10);                                                                          //业界资讯
	$smarty->assign('yjzx',$yjzx);

	$rdzx = $siteObj->getnewslist(4,'',10);                                                                          //热点资讯
	$smarty->assign('rdzx',$rdzx);

    
}

$smarty->assign('backaddress',$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
$cachepath1=substr($my_cache_id,0,2);
$cachepath2=substr($my_cache_id,2,2);

$smarty->display($tplpath.'news/index.html',$cachepath1.'|'.$cachepath2.'|'.$my_cache_id); 
?>